# Author: Mr.Xu
# @Time : 2019/12/19 11:20
from . import models
from rest_framework import serializers

class CategoryModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Category
        fields = ('id', 'name')

class RegionModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Region
        fields = ('id', 'name')

class TypeModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Type
        fields = ('id', 'name')

class PeriodModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Period
        fields = ('id', 'name')

class VideoModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Video
        fields = [
            "id",
            "title",
            "other_title",
            "score",
            "image_url",
            "heat",
            "order",
            "desc",
            "is_free",
            "sections_status",
            "pub_time",
            "star",
            "category_name",
            "region_name",
            "period_name",
            "types_name",
            "get_directors",
            "get_casts",
            "get_authors",
            "get_section_pks",
            "get_section_names",
            "get_section_pubTime"
        ]


class VideoSectionModelSerializer(serializers.ModelSerializer):
    # 子序列化必须用表中的外键字段
    video = VideoModelSerializer()
    class Meta:
        model = models.Video_Section
        fields = ["video", "v_id", "name", "pub_time", "link", "desc", "order", "image_url"]


class LeaderboardSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Video
        fields = ["id", "title","sections_status","image_url"]